Perform xenbus operations in shutdown_handler in a transaction.
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Tue, 13 Sep 2005 21:29:28 +0000 (21:29 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Tue, 13 Sep 2005 21:29:28 +0000 (21:29 +0000)
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
linux-2.6-xen-sparse/arch/xen/kernel/reboot.c

index b6608cef497a9102472bb44c1d5531975dbfa7e4..12c7610e90a13d15a9e2876a783372f9d6025881 100644 (file)
@@ -320,20 +320,28 @@ static void __shutdown_handler(void *unused)
 static void shutdown_handler(struct xenbus_watch *watch, const char *node)
 {
     static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
-
     char *str;
+    int err;
 
+ again:
+    err = xenbus_transaction_start("control");
+    if (err)
+       return;
     str = (char *)xenbus_read("control", "shutdown", NULL);
-    /* Ignore read errors. */
-    if (IS_ERR(str))
-        return;
-    if (strlen(str) == 0) {
-        kfree(str);
-        return;
+    /* Ignore read errors and empty reads. */
+    if (XENBUS_IS_ERR_READ(str)) {
+       xenbus_transaction_end(1);
+       return;
     }
 
     xenbus_write("control", "shutdown", "", O_CREAT);
 
+    err = xenbus_transaction_end(0);
+    if (err == -ETIMEDOUT) {
+       kfree(str);
+       goto again;
+    }
+
     if (strcmp(str, "poweroff") == 0)
         shutting_down = SHUTDOWN_POWEROFF;
     else if (strcmp(str, "reboot") == 0)